package com.cleargroup.magic.cleara.c.command;

import android.content.Context;

import java.util.ArrayList;
import java.util.List;

public abstract class ExaminableCommand implements ICommand, IExaminable,
        ExaminableCommandListener, ICancelable {

	private ExaminableCommandListener listener;
	private boolean inThreadPool = false;
	private boolean isCanceled = false;
	private Context context;
	private String key;

	public ExaminableCommand(Context context) {
		this.setContext(context);
	}

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}

	public ExaminableCommandListener getListener() {
		return listener;
	}

	public void setListener(ExaminableCommandListener listener) {
		this.listener = listener;
	}

	public void removeListener() {
		this.setListener(null);
	}

	public boolean isCanceled() {
		return isCanceled;
	}

	public void setCanceled(boolean isCanceled) {
		this.isCanceled = isCanceled;
	}

	protected void onExamined(Context context, long amount, long size) {
		if (getListener() != null) {
			getListener().onExamined(context, this, amount, size);
		}
	}

	protected void onExecuted(Context context, long amount, long size) {
		if (getListener() != null) {
			getListener().onExecuted(context, this, amount, size);
		}
	}

	public void onExamining(Progress progress) {

	}

	public void onExamined(Context context, ExaminableCommand command, long amount, long size) {

	}

	public void onExecuting(Progress progress) {
	}

	public void onExecuted(Context context, ExaminableCommand command,
			long amount, long size) {
	}

	public void examine() {
	}

	public void execute(List... list) {
	}

	public void examine(ArrayList<String> pathList){}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public boolean inThreadPool() {
		return inThreadPool;
	}

	public void setInThreadPool(boolean inThreadPool) {
		this.inThreadPool = inThreadPool;
	}

	public class Progress {
		private ExaminableCommand command;
		private Object obj;
		private String msg;
		private int arg1;
		private int arg2;
		private long size;

		public long getSize() {
			return size;
		}

		public void setSize(long size) {
			this.size = size;
		}

		public Progress(ExaminableCommand command) {
			this.setCommand(command);
		}

		public ExaminableCommand getCommand() {
			return command;
		}

		public void setCommand(ExaminableCommand command) {
			this.command = command;
		}

		public Object getObj() {
			return obj;
		}

		public void setObj(Object obj) {
			this.obj = obj;
		}

		public int getArg1() {
			return arg1;
		}

		public void setArg1(int arg1) {
			this.arg1 = arg1;
		}

		public int getArg2() {
			return arg2;
		}

		public void setArg2(int arg2) {
			this.arg2 = arg2;
		}

		public String getMsg() {
			return msg;
		}

		public void setMsg(String msg) {
			this.msg = msg;
		}

		@Override
		public String toString() {
			return "Progress{" +
					"command=" + command +
					", obj=" + obj +
					", msg='" + msg + '\'' +
					", arg1=" + arg1 +
					", arg2=" + arg2 +
					", size=" + size +
					'}';
		}
	}
}
